<?php
/**
 * Created by PhpStorm.
 * User: jswei
 * Date: 2018/5/3
 * Time: 14:06
 */
namespace app\first\model;

use think\Model;

class Filter extends Model{
    /**
     * @param $uid
     * @param $rid
     * @param string $out
     * @return bool
     */
    public function addNew($uid,$rid,&$out=''){
        if(!$uid && !$rid){
            $out='缺少参数';
            return false;
        }
        $count = $this
            ->where('mid','eq',$uid)
            ->where('rid','eq',$rid)
            ->count();
        if($count){
            $out='您已近屏蔽该用户了';
            return false;
        }
        $data = [
            'mid'=>$uid,
            'rid'=>$rid
        ];
        if(!$this->save($data)){
          $out='操作失败';
          return false;
        }
        return true;
    }

    /**
     * @param $mid
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getFilterIds($mid){
        $list = $this->field('id,rid,mid')->whereIn('mid',$mid)->select();
        $_id=[];
        foreach ($list as $k => $v){
            array_push($_id,$v['rid']);
        }
        return $_id;
    }
}